package ANDROID_UF_MEDIARECORDER;

public class Example {
    public boolean onKeyDown(final int keyCode, final KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            MediaRecorder mRecorder = new MediaRecorder();

            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            final File file = new File("test.raw");
            if (file.exists()) {
                mRecorder.release();
            } else {
                mRecorder.setOutputFile(file.getPath());
            }

            mRecorder.start();
            mRecorder.release();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
